package com.empire.module.sporttery.service.football500firstbuy;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500firstbuy.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500firstbuy.Football500FirstBuyDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500firstbuy.Football500FirstBuyMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 500wan 必发大额交易明细 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500FirstBuyServiceImpl implements Football500FirstBuyService {

    @Resource
    private Football500FirstBuyMapper football500FirstBuyMapper;

    @Override
    public Integer createFootball500FirstBuy(Football500FirstBuySaveReqVO createReqVO) {
        // 插入
        Football500FirstBuyDO football500FirstBuy = BeanUtils.toBean(createReqVO, Football500FirstBuyDO.class);
        football500FirstBuyMapper.insert(football500FirstBuy);
        // 返回
        return football500FirstBuy.getId();
    }

    @Override
    public void updateFootball500FirstBuy(Football500FirstBuySaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500FirstBuyExists(updateReqVO.getId());
        // 更新
        Football500FirstBuyDO updateObj = BeanUtils.toBean(updateReqVO, Football500FirstBuyDO.class);
        football500FirstBuyMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500FirstBuy(Integer id) {
        // 校验存在
        validateFootball500FirstBuyExists(id);
        // 删除
        football500FirstBuyMapper.deleteById(id);
    }

    private void validateFootball500FirstBuyExists(Integer id) {
        if (football500FirstBuyMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_FIRST_BUY_NOT_EXISTS);
        }
    }

    @Override
    public Football500FirstBuyDO getFootball500FirstBuy(Integer id) {
        return football500FirstBuyMapper.selectById(id);
    }

    @Override
    public PageResult<Football500FirstBuyDO> getFootball500FirstBuyPage(Football500FirstBuyPageReqVO pageReqVO) {
        return football500FirstBuyMapper.selectPage(pageReqVO);
    }

}